package com.kaibes.web.admin;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import com.kaibes.web.prefix.PrefixContext;
import com.kaibes.web.prefix.PrefixTarget;

@Component
public class AdminStartedListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        ApplicationContext applicationContext = event.getApplicationContext();
        
        PrefixContext prefixContext = applicationContext.getBean(PrefixContext.class);
        PrefixTarget prefixTarget = prefixContext.findPrefixTarget("admin");
        if (prefixTarget == null) {
            prefixTarget = new PrefixTarget();
            prefixTarget.setPrefix("admin"); //前缀路径
            prefixTarget.setTarget("admin-base"); //目标路径
            prefixContext.addPrefixTarget(prefixTarget);
        }
        
    }

}
